import request from "/utils/request.ts";
import {token} from "../stores/user";

export interface TrainingListRequest {
  trainingTitle?: string // 培训名称
  trainingType?: string // 培训类型
  trainingStatus?: 0 | 1 | 2 | 3 | '' // 培训状态(0未开始1已开始2已结束3查询全部课程，默认为空则查询0,1状态)
  pageNum: number
  pageSize: number
}

// 查询培训列表
export const getTrainingList = (data: TrainingListRequest) =>
  request({
    url: '/classai/api/training/getTrainingList',
    method: 'get',
    data
  })

// 我的学分
export const getMyScore = (data: Request) =>
  request({
    url: '/classai/api/training/getMyScore',
    method: 'get',
    data
  })

/**
 * 查询培训详情
 * @param trainingId 培训ID
 */
export const getTrainingById = (trainingId: string) =>
  request({
    url: '/classai/api/training/getTrainingById',
    method: 'get',
    data: { trainingId }
  })

// 查询培训下的课程列表
export const getTrainingCourseList = (trainingId: string) =>
  request({
    url: '/classai/api/training/getTrainingCourseList',
    method: 'get',
    data: { trainingId }
  })

/**
 *  查询培训课程详情
 * @param trainingCourseId 培训课程ID
 */
export const getTrainingCourseById = (trainingCourseId: string) =>
  request({
    url: '/classai/api/training/getTrainingCourseById',
    method: 'get',
    data: { trainingCourseId }
  })

/**
 *  查询线上课程视频
 * @param trainingCourseId 培训课程ID
 */
export const getCourseVideoList = (trainingCourseId: string) =>
  request({
    url: '/classai/api/training/getCourseVideoList',
    method: 'get',
    data: { trainingCourseId }
  })

/**
 *  查询课程资料
 * @param trainingCourseId 培训课程ID
 */
export const getCourseDocumentList = (trainingCourseId: string) =>
  request({
    url: '/classai/api/training/getCourseDocumentList',
    method: 'get',
    data: { trainingCourseId }
  })

/**
 *  查询课后作业
 * @param trainingCourseId 培训课程ID
 */
export const getHomeworkList = (trainingCourseId: string) =>
  request({
    url: '/classai/api/training/getHomeworkList',
    method: 'get',
    data: { trainingCourseId }
  })

  /**
 *  查询课后作业状态
 * @param trainingCourseId 培训课程ID
 */
export const getTrainingCourseStatus = (trainingCourseId: string) =>
  request({
    url: '/classai/api/training/getTrainingCourseStatus',
    method: 'get',
    data: { trainingCourseId }
  })

/**
 *  查询扫码签到
 * @param scanCodeSignin 培训课程ID
 */
export const scanCodeSignin = (trainingCourseId: string) =>
  request({
    url: '/classai/api/training/scanCodeSignin',
    method: 'get',
    data: { trainingCourseId }
  })


/**
 *  查询问卷调查
 * @param trainingCourseId 培训课程ID
 */
export const getQuestionnaireList = (trainingCourseId: string) =>
  request({
    url: '/classai/api/training/getQuestionnaireList',
    method: 'get',
    data: { trainingCourseId }
  })

/**
 * 课后作业提交
 */
export class AddHomeworkItem {
  trainingCourseId: string = '' // 培训课程id
  homeworkName: string = '' // 作业名称
  homeworkUrl: string = '' // 作业地址
  teacherId: string = '' // 老师id
}

export async function addHomework(data: AddHomeworkItem) {
  return request({
    url: '/classai/api/training/addHomework',
    method: 'post',
    data
  })
}

/**
 * 问卷调查提交
 */
export class AddQuestionnaireItem {
  trainingCourseId: string = '' // 培训课程id
  questionnaireId: string = '' // 问卷id
  questionnaireContent: string = '' // 问卷内容
  teacherId: string = '' // 老师id
}

export async function addQuestionnaire(data: AddQuestionnaireItem[]) {
  return request({
    url: '/classai/api/training/addQuestionnaire',
    method: 'post',
    data
  })
}

/**
 * 课程视频提交
 */
export class AddCourseVideoItem {
  trainingCourseId: string = '' // 培训课程id
  teacherId: string = '' // 老师id
  videoId: string = '' // 视频ID
  videoProgress: string = '' // 视频进度
  videoDuration: string = '' // 视频时长
  status: 0 | 1 = 0 // 0未完成1已完成
}

export async function addCourseVideo(data: AddCourseVideoItem) {
  return request({
    url: '/classai/api/training/addCourseVideo',
    method: 'post',
    data
  })
}

/**
 *  我的消息列表(教师端/小程序)
 *
 */
export const getMyMessageList = (data) =>
  request({
    url: '/classai/api/training/getMyMessage',
    method: 'get',
    data: data
  })
/**
 *  设置消息已读(教师端/小程序)
 *
 */
export const getreadMessage = (data) =>
  request({
    url: '/classai/api/training/readMessage',
    method: 'get',
    data: data
  })
/**
 *  我的学分(教师端/小程序)
 *
 */
export const getgetMyScoreLi = (data) =>
  request({
    url: '/classai/api/training/getMyScore',
    method: 'get',
    data
  })

/**
 *  查询消息详情(教师端/小程序)
 *
 */
export const getMyMessageById = (msgId: string) =>
  request({
    url: '/classai/api/training/getMyMessageById',
    method: 'get',
    data: { msgId }
  })

// 查询字典表类型
export async function getDictType(type: string) {
  return request({
    url: '/classai/api/resource/getDictType',
    method: 'get',
    data: { dictType: type },
    checkToken: true
  })
}

// 上传资源
// export async function uploadFile(file) {
//   return request({
//     url: '/file/upload',
//     method: 'post',
//     data: { file },
//     headers: {
//       'content-type': 'multipart/form-data'
//     },
//     checkToken: true
//   })
// }
